var base = null
var utils = null
var azurCtrl = null
var server = null
var map
func _ready():
	pass
func _init():
	call_deferred("omgInit")
	pass
func _connect():
	pass

func omgInit():
	if globalData.infoDs.has("g_azurlaneBase"):
		base = globalData.infoDs["g_azurlaneBase"]
	if base != null:
		#初始化
		utils = globalData.infoDs["g_azurlaneUtils"]
		server = globalData.infoDs["g_azurlaneServer"]
		map = globalData.infoDs["g_azurlaneMap"]
		azurCtrl = globalData.infoDs["g_azurlane"]
		azurCtrl.connect("resetData", self, "resetData")
		base.connect("onNewGame",self,"gameCtrl")
		azurCtrl.connect("onLoadGame",self,"loadGame")

func loadGame():
	var tmp = base.getData("omg", {})

func onSaveGame():
	# var tmp = {}
	# tmp["skillRecord"] = skillRecord
	# tmp["planes"] = planes
	# tmp["chasRndIds"] = chasRndIds
	# base.setData("omg", tmp)
	# research.onSaveGame()
	pass
		
func resetData():
	skillRecord = {}
	chasRndIds = []

func gameCtrl():
	# sys.main.player.plusGold(950)
	# azurCtrl.pt = 1000
	yield(sys.get_tree().create_timer(1), "timeout")
	if not sys.test:return
	
	sys.main.guankaMsg.lvStep = 133
	sys.main.batLLv = 4

	map.createMap27()

	sys.main.player.plusEmp(40000)

	sys.main.player.addCha(sys.main.newChara("toolman"))
	sys.main.player.addCha(sys.main.newChara("nandaketa-4"))
	sys.main.player.addCha(sys.main.newChara("jiahe-4"))
	sys.main.player.addCha(sys.main.newChara("ankeleiqi-4"))
	# sys.main.player.addCha(sys.main.newChara("aijier-1"))
	# sys.main.player.addCha(sys.main.newChara("bailong-4"))
	# sys.main.player.addCha(sys.main.newChara("buleisite-4"))
	# sys.main.player.addCha(sys.main.newChara("pulimaosi-4"))
	# sys.main.player.addCha(sys.main.newChara("ruihe-4"))
	sys.main.player.addCha(sys.main.newChara("toolmanGM"))
	sys.main.player.plusGold(9500)
	azurCtrl.changeBuli(30)
	azurCtrl.changeMF(20000)

	# var keyboard = utils.loadScript("Keyboard")
	# sys.main.get_node("ui").add_child(keyboard)
	sys.main.keyboard.connect("key_j", self, "test")
	sys.main.keyboard.connect("key_k", self, "test2")
	sys.main.keyboard.connect("key_l", self, "test3")

func test():
	for i in utils.getAllCells(2):
		var cha = sys.main.matCha(i)
		if cha != null and cha.team != 1: 
			sys.main.delMatChara(cha)
	for i in range(5, 7):
		for j in range(0, 6):
			var cell = Vector2(i, j)
			var matcha = sys.main.matCha(cell)
			if matcha != null:
				sys.main.delMatChara(matcha)
			var cha = sys.main.newChara("toolman", 2)
			sys.main.map.add_child(cha)
			sys.main.setMatCha(cell, cha)
	# server.upload()

func test2():
	pass

func test3():
	# server.loadTeamInfo(1)
	pass

func test4():
	pass
	

#生成角色唯一ID
func generateChaId():
	var rid = sys.rndRan(10000, 99999)
	while chasRndIds.has(rid):
		rid = sys.rndRan(10000, 99999)
	chasRndIds.append(rid)
	return rid

var chasRndIds = []
var skillRecord = {}

